import JSEncrypt from "jsencrypt" // 处理长文本数据时报错 jsencrypt.js Message too long for RSA
import Encrypt from "encryptlong" // encryptlong是基于jsencrypt扩展的长文本分段加解密功能。
const publickey =
  "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAleOM3njO5iBH1eX9XFC7rdf0+CsIQ1/wL2PtZzIH/5/xzLfNCYhbeHT9q7DWgqtzF43Pyty1oWwGI0jsFmVO4wIDAQABAkACIkQuIqAnbIw5QlXyC4AwgGOPaOVsOCBuPEjz8CVnATVXIWCCMgItFnlhuDtkP0NvcyDnyFtnRkStsePP+IC5AiEAxfLClg6/aJgATyoxkyv9wgt61BxmYIq1Go+R8/lSfSUCIQDB2Knbuim0Sna/dubzFksAJfxi38d/uCRph3xi4xeRZwIgEDLMb6EnUrTVmaTXR7ba3i04UPE+A3p2VYUYKYHmmS0CIFrLylvyKeCZ1F9AKVMJSR4LrNj/KmnHbb7ESF3lMr/XAiEAw1+ONco8tH/qfObcde0aNQn5dx/MXQal67xMypfeLn8="
/*JSEncrypt加密*/
export const rsaPublicData = (data: any) => {
  const jsencrypt = new JSEncrypt()
  jsencrypt.setPublicKey(publickey)
  //如果是对象/数组的话，需要先JSON.stringify转换成字符串
  const result = jsencrypt.encrypt(data)
  return result
}

export const encrypt = (data: any) => {
  const PUBLIC_KEY = publickey
  const encryptor = new Encrypt()
  encryptor.setPublicKey(PUBLIC_KEY)
  //如果是对象/数组的话，需要先JSON.stringify转换成字符串
  const result = encryptor.encryptLong(data)
  return result
}
